import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:terminal_flutter_demo/pages/getxpages/controllers/user.dart';

class GetXHomePage extends StatefulWidget {
  const GetXHomePage({Key? key}) : super(key: key);

  @override
  _GetXHomePageState createState() => _GetXHomePageState();
}

class _GetXHomePageState extends State<GetXHomePage> {
  final userController = Get.put(UserController());

  @override
  Widget build(BuildContext context) {
    print('-----------');
    print(Get.arguments);
    return Scaffold(
      appBar: AppBar(
        title: const Text('home'),
      ),
      body: Center(
        child: Column(
          children: [
            GetBuilder<UserController>(builder: (_) {
              return Text('token: ${userController.token}');
            }),
            const SizedBox(height: 30),
            Text('arguments token: ${userController.token}'),
            const SizedBox(height: 30),
            Text('UserController token: ${userController.user.value.token}'),
            const SizedBox(height: 30),
            ElevatedButton.icon(
              icon: const Icon(Icons.shop),
              onPressed: () {
                Get.toNamed(
                  '/shop',
                  // 传参
                  arguments: {
                    'id': 123,
                  },
                );
              },
              label: const Text('商店'),
            ),
            const SizedBox(height: 30),
            ElevatedButton.icon(
              icon: const Icon(Icons.login),
              onPressed: () {
                Get.toNamed(
                  '/login',
                  arguments: {
                    'id': 123,
                  },
                );
              },
              label: const Text('登录'),
            ),
            const SizedBox(height: 30),
            ElevatedButton.icon(
              icon: const Icon(Icons.home),
              onPressed: () {
                // Get.toNamed('/');
                Get.back();
              },
              label: const Text('去首页'),
            ),
          ],
        ),
      ),
    );
  }
}
